home *** CD-ROM | disk | FTP | other *** search
/ Savor the Moment - Entert…ing Without Reservations / Savoe the Moment - Entertaining Without Reservations.iso / pc / show.dxr / 00052_Cycle Graphics.ls < prev    next >
Encoding:
Text File  |  1999-10-03  |  9.9 KB  |  245 lines

  1. property spriteNum, mySprite, myFirstMember, myLastMember, myFrameTime, myTimeUnit, myPlayBackwards, myMembersList, myMemberCount, myCurrentMember, myListPosition, myLoopFlag, myMilliseconds
  2.  
  3. on getBehaviorDescription me
  4.   return "CYCLE GRAPHICS" & RETURN & RETURN & "This behavior cycles through a series of consecutive cast members" & RETURN & RETURN & "It gives you all the features of a single member filmloop, plus the possibility of precise control via Lingo.  These possibilities include speed control, starting and stopping at an arbitrary image, modifying the list of images to cycle through and more. (See 'Public Methods' below)" & RETURN & RETURN & "You simply arrange your castmembers in the order they should appear in the cycle, then use the Behavior Parameters dialog to indicate the first and last images.  You can use any type of visual member, including fields, text and buttons.  Spaces between cast members will be ignored." & RETURN & RETURN & "The regPoint of each member will appear at the loc of the current sprite.  If necessary, modify the regPoint of each member individually so that it appears in the correct position relative to the other members of the cycle." & RETURN & RETURN & "If you shift the members to different cast slots, you will need to alter the settings in the Behavior Parameters dialog: a film loop can keep track of where you drag its members to, but this behavior cannot do that." & RETURN & RETURN & "The images cannot cycle faster than the current frame tempo.  If you need to cycle faster, either increase the tempo or reduce the number of images in the list.  At speeds of more than 60 images per second, the human eye is incapable of distinguishing individual images, so higher speeds are unnecessary." & RETURN & RETURN & "PERMITTED MEMBER TYPES:" & RETURN & "#bitmap, #button, #field, #filmLoop, #flash, #movie," & RETURN & "#quickTimeMedia, #shape, #text, #vectorShape." & RETURN & RETURN & "PARAMETERS:" & RETURN & "* First/Last members: indicate which cast members to use." & RETURN & "* Rate of display of images (120 fps to 2 hours per image)" & RETURN & "* Cycle forwards or backwards" & RETURN & "* Start cycling images on beginsprite? (TRUE | FALSE)" & RETURN & "If you choose not to start cycling images on beginsprite, then you need to send a #CycleGraphics_ToggleLoop message to the sprite or the behavior to make the cycle start." & RETURN & RETURN & "PUBLIC METHODS:" & RETURN & "=> Determine which image is currently showing" & RETURN & "=> Cycle images at the frameTempo or slower" & RETURN & "=> Play the images forwards or backwards" & RETURN & "=> Start and stop at an arbitrary image" & RETURN & "=> Jump to a given image" & RETURN & "=> Determine or modify the list of images to cycle through" & RETURN & "=> Obtain the behavior reference."
  5. end
  6.  
  7. on getBehaviorTooltip me
  8.   vTip = "Use with any graphic member, including text" & RETURN
  9.   vTip = vTip & "and buttons.  This behavior cycles through" & RETURN
  10.   vTip = vTip & "a series of images at a rate independant of" & RETURN
  11.   vTip = vTip & "the frameTempo.  It gives you all the features" & RETURN
  12.   vTip = vTip & "of a single member film loop, plus precise" & RETURN
  13.   vTip = vTip & "control via Lingo.  You can stop/start the cycle," & RETURN
  14.   vTip = vTip & "alter the speed, jump to an arbitrary member," & RETURN
  15.   vTip = vTip & "reverse the direction of the cycle, get and set" & RETURN
  16.   vTip = vTip & "the list of membersto cycle through, and determine" & RETURN
  17.   vTip = vTip & "which image is currently showing." & RETURN & RETURN
  18.   vTip = vTip & "See the 'Notes for developers' in the script" & RETURN
  19.   vTip = vTip & "for more details."
  20.   return vTip
  21. end
  22.  
  23. on beginSprite me
  24.   Initialize(me)
  25. end
  26.  
  27. on prepareFrame me
  28.   Update(me)
  29. end
  30.  
  31. on Initialize me
  32.   mySprite = sprite(me.spriteNum)
  33.   case myTimeUnit of
  34.     "images per second":
  35.       myFrameTime = 1000 / myFrameTime
  36.     "ticks per image":
  37.       myFrameTime = myFrameTime * 1000 / 60
  38.     "seconds per image":
  39.       myFrameTime = myFrameTime * 1000
  40.     "minutes per image":
  41.       myFrameTime = myFrameTime * 1000 * 60
  42.   end case
  43.   case myPlayBackwards of
  44.     #forwards:
  45.       myPlayBackwards = 0
  46.     #backwards:
  47.       myPlayBackwards = 1
  48.     otherwise:
  49.       return #invalidSymbolError
  50.   end case
  51.   myFirstMember = member(myFirstMember)
  52.   myLastMember = member(myLastMember)
  53.   minMember = min(myFirstMember.number, myLastMember.number)
  54.   maxMember = max(myFirstMember.number, myLastMember.number)
  55.   myMembersList = []
  56.   repeat with memberNumber = minMember to maxMember
  57.     theMember = member(memberNumber)
  58.     myMembersList.append(theMember)
  59.   end repeat
  60.   checkedList = StripNonGraphicMembers(me, duplicate(myMembersList))
  61.   if checkedList <> myMembersList then
  62.     ErrorAlert(me, #invalidMembers)
  63.   end if
  64.   myMemberCount = myMembersList.count()
  65.   if myPlayBackwards then
  66.     myListPosition = 1
  67.   else
  68.     myListPosition = myMemberCount
  69.   end if
  70.   myMilliseconds = the milliSeconds
  71. end
  72.  
  73. on Update me
  74.   if not myLoopFlag then
  75.     exit
  76.   end if
  77.   elapsedTime = the milliSeconds - myMilliseconds
  78.   if abs(elapsedTime < myFrameTime) then
  79.     exit
  80.   else
  81.     if elapsedTime > (myFrameTime * 2) then
  82.       myMilliseconds = the milliSeconds
  83.     end if
  84.   end if
  85.   myMilliseconds = myMilliseconds + myFrameTime
  86.   if myPlayBackwards then
  87.     myListPosition = myListPosition - 2 + myMemberCount
  88.   end if
  89.   myListPosition = (myListPosition mod myMemberCount) + 1
  90.   myCurrentMember = myMembersList[myListPosition]
  91.   mySprite.member = myCurrentMember
  92. end
  93.  
  94. on CycleGraphics_GetCurrentMember me
  95.   return myCurrentMember
  96. end
  97.  
  98. on CycleGraphics_GetMembersList me
  99.   return myMembersList
  100. end
  101.  
  102. on CycleGraphics_ToggleLoop me, trueOrFalse
  103.   if voidp(trueOrFalse) then
  104.     myLoopFlag = not myLoopFlag
  105.   else
  106.     if ilk(trueOrFalse) <> #integer then
  107.       return #invalidTypeError
  108.     else
  109.       myLoopFlag = trueOrFalse
  110.     end if
  111.   end if
  112.   if myLoopFlag then
  113.     myMilliseconds = the milliSeconds
  114.   end if
  115. end
  116.  
  117. on CycleGraphics_ToggleDirection me, playBackwards
  118.   if voidp(playBackwards) then
  119.     myPlayBackwards = not myPlayBackwards
  120.   else
  121.     case playBackwards of
  122.       #forward, #forwards, 0:
  123.         myPlayBackwards = 0
  124.       #back, #backward, #backwards, #Reverse, 1:
  125.         myPlayBackwards = 1
  126.       otherwise:
  127.         return #invalidSymbolError
  128.     end case
  129.   end if
  130.   myMilliseconds = the milliSeconds
  131. end
  132.  
  133. on CycleGraphics_ShowImage me, theImage
  134.   case ilk(theImage) of
  135.     #integer:
  136.       if (theImage < 1) or (theImage > myMemberCount) then
  137.         return #outOfRangeError
  138.       else
  139.         myListPosition = theImage
  140.         myCurrentMember = myMembersList[myListPosition]
  141.       end if
  142.     #member:
  143.       listPosition = myMembersList.getPos(theImage)
  144.       if listPosition then
  145.         myCurrentMember = theImage
  146.         myListPosition = listPosition
  147.       else
  148.         return #notInListError
  149.       end if
  150.     otherwise:
  151.       return #invalidTypeError
  152.   end case
  153.   mySprite.member = myCurrentMember
  154.   myMilliseconds = the milliSeconds
  155.   updateStage()
  156. end
  157.  
  158. on CycleGraphics_SetFrameTime me, theMilliseconds
  159.   if ilk(theMilliseconds) <> #integer then
  160.     return #invalidTypeError
  161.   else
  162.     if ilk(theMilliseconds) < 0 then
  163.       return #outOfRangeError
  164.     end if
  165.   end if
  166.   myFrameTime = theMilliseconds
  167. end
  168.  
  169. on CycleGraphics_SetMembersList me, membersList
  170.   if ilk(membersList) <> #list then
  171.     return #invalidTypeError
  172.   end if
  173.   StripNonGraphicMembers(me, membersList)
  174.   if not membersList.count() then
  175.     return #emptyListError
  176.   end if
  177.   myMembersList = membersList
  178.   myMemberCount = myMembersList.count()
  179.   if myPlayBackwards then
  180.     myListPosition = 1
  181.   else
  182.     myListPosition = myMemberCount
  183.   end if
  184. end
  185.  
  186. on CycleGraphics_GetReference me, theList
  187.   case ilk(theList) of
  188.     #list:
  189.       theList.append(me)
  190.     #propList:
  191.       theList.addProp(me.spriteNum, me)
  192.     otherwise:
  193.       return me
  194.   end case
  195.   return theList
  196. end
  197.  
  198. on StripNonGraphicMembers me, membersList
  199.   permittedTypes = [#bitmap, #button, #field, #filmLoop, #flash, #movie, #picture, #quickTimeMedia, #shape, #text, #vectorShape]
  200.   i = membersList.count()
  201.   repeat while i
  202.     theMember = membersList[i]
  203.     if ilk(theMember) <> #member then
  204.       alert("'Cycle Graphics' behavior - not a member: " & theMember)
  205.       membersList.deleteAt(i)
  206.     else
  207.       if not permittedTypes.getPos(theMember.type) then
  208.         alert("'Cycle Graphics' behavior - invalid member: " & theMember)
  209.         membersList.deleteAt(i)
  210.       end if
  211.     end if
  212.     i = i - 1
  213.   end repeat
  214.   return membersList
  215. end
  216.  
  217. on ErrorAlert me, theError, data
  218.   behaviorName = string(me)
  219.   delete word 1 of behaviorName
  220.   delete char -30001 of behaviorName
  221.   delete char -30001 of behaviorName
  222.   case data.ilk of
  223.     #void:
  224.       data = "<void>"
  225.     #symbol:
  226.       data = "#" & data
  227.   end case
  228.   case theError of
  229.     #invalidMembers:
  230.       if the runMode <> "Author" then
  231.         exit
  232.       end if
  233.       alert("BEHAVIOR ERROR: Frame " & the frame & ", Sprite " & me.spriteNum & RETURN & "Behavior " & behaviorName & RETURN & RETURN & "Certain members between " & myFirstMember & " and " & myLastMember & " are not graphical members.  Check the permitted types list for valid types.")
  234.   end case
  235. end
  236.  
  237. on getPropertyDescriptionList
  238.   if not (the currentSpriteNum) then
  239.     exit
  240.   end if
  241.   theMember = sprite(the currentSpriteNum).member
  242.   theMemberNumber = theMember.number
  243.   return [#myFirstMember: [#comment: "First member of series:", #format: #graphic, #default: theMember], #myLastMember: [#comment: "Last member of series:", #format: #graphic, #default: member(theMemberNumber + 1)], #myFrameTime: [#comment: "Display images at a maximum speed of:", #format: #integer, #range: [#min: 1, #max: 120], #default: min(the frameTempo, 120)], #myTimeUnit: [#comment: EMPTY, #format: #string, #range: ["images per second", "ticks per image", "seconds per image", "minutes per image"], #default: "images per second"], #myPlayBackwards: [#comment: "Cycle:", #format: #symbol, #range: [#forwards, #backwards], #default: #forwards], #myLoopFlag: [#comment: "Start cycling on beginSprite?", #format: #boolean, #default: 1]]
  244. end
  245.